I am trying to use the function copyHier to copy an object heading and its descendants to another module but it seems that this function only works within the same module. |
Re: copyHier Anyway, you don't need the clipboard at all: You can copy a module with bool copy(ModName_ modRef, string newName, string newdesc) If you really need to copy each object individually, I suggest you use the example script DOORSHOME/lib/dxl/example/copyobj.dxl |
Re: copyHier ePiallat - Mon Nov 09 11:46:22 EST 2009 If you read my previous post I asked how I can perform a similar function to copying all the objects over, I'm already aware of the bool copy function and how it works, and it does not fulfill what I am trying to do, I'm not trying to copy the module-as I've already said-I'm trying to duplicate the data to a template. I haven't explicitly looked through copyobj.dxl but I've looked through scripts that co-workers have written based on this script and it seems very complex and convoluted for the ideas that I'm trying to implement. I was looking at copyHier because if you use the DOORS gui, you can do what I'm attempting to do in DXL, with a few simple mouse clicks. I was trying to find the code that was used to implement those functions in the gui and it appeared that copyHier was the closest thing. FOR EXAMPLE: In the gui, if you open two separate modules, in the first module, you can grab an object heading with the mouse and drag it to the second module, at which point a list comes up and you can select "Copy->After (with hierarchy)" It appears that this is the copyHier function but as I said, I can only get this function to work within the same module, not from one module to the next. If it helps, this script is being written for 8.3. |
Re: copyHier John V - Mon Nov 09 12:59:24 EST 2009 It seems you need to manually write a copy function. Regards, Mathias |
Re: copyHier John V - Mon Nov 09 12:59:24 EST 2009
I understand better now, but I'm afraid you can't use the "pasteSame" function to copy into another module.
// copyHierarchy.dxl
/**
* Minimal subset from: /DOORS/lib/dxl/example/copyobj.dxl
* Launch "copyAllVisible" without displaying a DB
*
* @author epiallat
* @date 10 nov. 2009
*/
// change source and target here
Module targetMod = edit "Target"
Module sourceMod = read "Source"
#include <example/include/copyops.inc>
const int createAfter = 0
const int createBelow = 1
const int createLastBelow = 2
void copyObject (Object s, t) {
if (s==t) return
string attrName = ""
copyAttribute_(s,t,"Object Text")
copyAttribute_(s,t,"Object Heading")
copyAttribute_(s,t,"Object Short Text")
if (cell s)
{ // copy across the table border attributes if the object is a cell
copyAttribute_(s,t,"TableTopBorder")
copyAttribute_(s,t,"TableBottomBorder")
copyAttribute_(s,t,"TableLeftBorder")
copyAttribute_(s,t,"TableRightBorder")
copyAttribute_(s,t,"TableCellWidth")
copyAttribute_(s,t,"TableCellAlign")
}
}
/* Check whether object o is a child of object check */
bool childOf(Object check, Object o) {
while (o!=check && o!=null)
o = parent o
return (o==check)
} /* childOf */
// Given a starting object, returns the next visible object
// (or null) which is not in the tree under the starting object
Object ftNextValidSkipTree(Object starto) {
Object checko
if (null starto)
return null
checko = next starto
while ((!null checko) && (childOf(starto, checko) || (!isVisible checko && !table checko && !row checko))) {
checko = next checko
}
if ((!null checko) && cell(checko)) {
/* Move to the table object */
checko = parent checko
checko = parent checko
}
return checko
}
// Returns first visible object in a module
Object ftFirstValid(Module m)
{
Object o = first m
while ((!null o) && (!isVisible o && !table o && !row o)) {
o = next o
}
return o
}
Object createNewObject(int copyPosition, Object tago)
{
Object newo
current = targetMod
if (null tago)
{ // no objects in destination module
if (isShare targetMod) {
ack "Target module is in edit shareable mode.\nCannot create initial object in target module."
halt
}
newo = create targetMod
}
else if (!canWrite tago)
{
ack "No permission to write to the current object in target module"
halt
}
else if (isShare targetMod && copyPosition == createAfter &&
(level tago == 1 || !canWrite parent tago))
{
ack "Target module is in edit shareable mode.\nNeed permission to write to the parent of the target object"
//raise d
halt
}
else if (copyPosition == createAfter)
{
newo = create after tago
}
else if (copyPosition == createBelow)
{
newo = create below tago
}
else if (copyPosition == createLastBelow)
{
newo = create last below tago
}
return newo
}
void copyVisibleTree(Object sourceUnder, targetUnder)
{
// Copy the (visible) tree under sourceUnder to be under targetUnder
// Also copy invisible objects that are table objects or row objects
Object sourceo
for sourceo in all sourceUnder do
{
if (isVisible sourceo || table sourceo || row sourceo)
{
Object targo = createNewObject(createLastBelow, targetUnder)
copyObject(sourceo, targo)
copyVisibleTree(sourceo, targo)
}
else
{
copyVisibleTree(sourceo, targetUnder)
}
}
}
current = targetMod
Object latcho = current
if (!null latcho) latcho = last sibling first targetMod
Object o, newo
copyDir = createAfter
// copy all visible trees
// get first visible object
o = ftFirstValid sourceMod
while (!null o)
{
// copy root of tree
newo = createNewObject(copyDir, latcho)
copyObject(o, newo)
// copy visible tree under it
copyVisibleTree(o, newo)
// step to next visible tree
o = ftNextValidSkipTree o
// move latcho if neccessary
if (copyDir == createAfter)
latcho = newo
}
|
Re: copyHier ePiallat - Tue Nov 10 04:01:23 EST 2009
I understand better now, but I'm afraid you can't use the "pasteSame" function to copy into another module.
// copyHierarchy.dxl
/**
* Minimal subset from: /DOORS/lib/dxl/example/copyobj.dxl
* Launch "copyAllVisible" without displaying a DB
*
* @author epiallat
* @date 10 nov. 2009
*/
// change source and target here
Module targetMod = edit "Target"
Module sourceMod = read "Source"
#include <example/include/copyops.inc>
const int createAfter = 0
const int createBelow = 1
const int createLastBelow = 2
void copyObject (Object s, t) {
if (s==t) return
string attrName = ""
copyAttribute_(s,t,"Object Text")
copyAttribute_(s,t,"Object Heading")
copyAttribute_(s,t,"Object Short Text")
if (cell s)
{ // copy across the table border attributes if the object is a cell
copyAttribute_(s,t,"TableTopBorder")
copyAttribute_(s,t,"TableBottomBorder")
copyAttribute_(s,t,"TableLeftBorder")
copyAttribute_(s,t,"TableRightBorder")
copyAttribute_(s,t,"TableCellWidth")
copyAttribute_(s,t,"TableCellAlign")
}
}
/* Check whether object o is a child of object check */
bool childOf(Object check, Object o) {
while (o!=check && o!=null)
o = parent o
return (o==check)
} /* childOf */
// Given a starting object, returns the next visible object
// (or null) which is not in the tree under the starting object
Object ftNextValidSkipTree(Object starto) {
Object checko
if (null starto)
return null
checko = next starto
while ((!null checko) && (childOf(starto, checko) || (!isVisible checko && !table checko && !row checko))) {
checko = next checko
}
if ((!null checko) && cell(checko)) {
/* Move to the table object */
checko = parent checko
checko = parent checko
}
return checko
}
// Returns first visible object in a module
Object ftFirstValid(Module m)
{
Object o = first m
while ((!null o) && (!isVisible o && !table o && !row o)) {
o = next o
}
return o
}
Object createNewObject(int copyPosition, Object tago)
{
Object newo
current = targetMod
if (null tago)
{ // no objects in destination module
if (isShare targetMod) {
ack "Target module is in edit shareable mode.\nCannot create initial object in target module."
halt
}
newo = create targetMod
}
else if (!canWrite tago)
{
ack "No permission to write to the current object in target module"
halt
}
else if (isShare targetMod && copyPosition == createAfter &&
(level tago == 1 || !canWrite parent tago))
{
ack "Target module is in edit shareable mode.\nNeed permission to write to the parent of the target object"
//raise d
halt
}
else if (copyPosition == createAfter)
{
newo = create after tago
}
else if (copyPosition == createBelow)
{
newo = create below tago
}
else if (copyPosition == createLastBelow)
{
newo = create last below tago
}
return newo
}
void copyVisibleTree(Object sourceUnder, targetUnder)
{
// Copy the (visible) tree under sourceUnder to be under targetUnder
// Also copy invisible objects that are table objects or row objects
Object sourceo
for sourceo in all sourceUnder do
{
if (isVisible sourceo || table sourceo || row sourceo)
{
Object targo = createNewObject(createLastBelow, targetUnder)
copyObject(sourceo, targo)
copyVisibleTree(sourceo, targo)
}
else
{
copyVisibleTree(sourceo, targetUnder)
}
}
}
current = targetMod
Object latcho = current
if (!null latcho) latcho = last sibling first targetMod
Object o, newo
copyDir = createAfter
// copy all visible trees
// get first visible object
o = ftFirstValid sourceMod
while (!null o)
{
// copy root of tree
newo = createNewObject(copyDir, latcho)
copyObject(o, newo)
// copy visible tree under it
copyVisibleTree(o, newo)
// step to next visible tree
o = ftNextValidSkipTree o
// move latcho if neccessary
if (copyDir == createAfter)
latcho = newo
}
|